package com.baidu.location;

import android.os.Handler;
import android.os.Message;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.util.EntityUtils;

final class af extends Thread
{
  public final void run()
  {
    int i = ae.d();
    while (true)
    {
      if (i > 0);
      try
      {
        Object localObject1 = new HttpPost(ak.f());
        Object localObject2 = new ArrayList();
        ((List)localObject2).add(new BasicNameValuePair("bloc", ae.e()));
        if (ae.f() != null)
          ((List)localObject2).add(new BasicNameValuePair("up", ae.f()));
        ((HttpPost)localObject1).setEntity(new UrlEncodedFormEntity((List)localObject2, "utf-8"));
        localObject2 = new DefaultHttpClient();
        ((HttpClient)localObject2).getParams().setParameter("http.connection.timeout", Integer.valueOf(ae.g()));
        ((HttpClient)localObject2).getParams().setParameter("http.socket.timeout", Integer.valueOf(ae.g()));
        HttpProtocolParams.setUseExpectContinue(((HttpClient)localObject2).getParams(), false);
        new StringBuilder("apn type : ").append(ae.h());
        ak.e();
        if ((((ae.h() == 1) || (ae.h() == 4))) && ((ae.d() - i) % 2 == 0))
        {
          new StringBuilder("apn type : ADD PROXY").append(ae.i()).append(ae.j());
          ak.e();
          HttpHost localHttpHost = new HttpHost(ae.i(), ae.j(), "http");
          ((HttpClient)localObject2).getParams().setParameter("http.route.default-proxy", localHttpHost);
        }
        localObject2 = ((HttpClient)localObject2).execute((HttpUriRequest)localObject1);
        int j = ((HttpResponse)localObject2).getStatusLine().getStatusCode();
        ak.e();
        if (j == 200)
        {
          localObject1 = EntityUtils.toString(((HttpResponse)localObject2).getEntity(), "utf-8");
          localObject2 = ((HttpResponse)localObject2).getEntity().getContentType();
          new StringBuilder("status error : ").append(localObject2);
          ak.e();
          localObject2 = ae.k().obtainMessage(21);
          ((Message)localObject2).obj = localObject1;
          ((Message)localObject2).sendToTarget();
          ae.l();
          if ((i <= 0) && (ae.k() != null))
          {
            ak.e();
            ae.k().obtainMessage(62).sendToTarget();
          }
          ae.m();
          ae.n();
          return;
        }
        ((HttpPost)localObject1).abort();
        localObject1 = ae.k().obtainMessage(63);
        ((Message)localObject1).obj = "HttpStatus error";
        ((Message)localObject1).sendToTarget();
        i -= 1;
      }
      catch (Exception localException)
      {
        while (true)
          localException.printStackTrace();
      }
    }
  }
}